<template>
  <div class="home">
    <!-- <img src="@/a" alt=""> -->
    <homeHeader />
    <search />
    <homeNav />
    <!-- <div class="main logo">
      <a :href="url">
        <img src="@/assets/img/zhaopinLogo.png" alt />
      </a>
    </div> -->
    <nav />
    <div class="main mt20">
      <router-view></router-view>
    </div>
    <footerMenu />
    <rightPopover />
  </div>
</template>
<script>
import { token } from '../../api/register';
import Vue from 'vue';
import bus from '../common/bus';
export default {
  name: '',
  data () {
    return {
      url: ''
    };
  },
  beforeRouteEnter (to, from, next) {
    token()
      .then(data => {
        console.log(data);
        if (data.code === 401 || data.code === 403) {
          console.log(3333)
          localStorage.removeItem('ep_Authorization');
          Vue.prototype.$message.error(`${data.msg}`);
          next({ path: '/login' });
          // next(vm => {
          //     vm.$message.error('您的登录状态已失效，请先登录！');
          //     next({ path: '/login' });
          // });
        } else if (!data.success) {
          console.log(777)
          localStorage.removeItem('ep_Authorization');
          Vue.prototype.$message.error(`${data.msg}`);
          next({ path: '/login' });
          // next(vm => {
          //     vm.$message.error(`${data.msg}`);
          //     next({ path: '/login' });
          // });
        } else {
          console.log(888)
          if (data.data) {
            sessionStorage.setItem('flag', data.data.authStatus === 2 && data.data.staffAuthStatus === 2)
            localStorage.setItem('ep_companyName', data.data.name)
            next();
          } else {
            next({ path: '/register' })
          }
          // bus.$emit('companyAuth', data.data.authStatus === 2 && data.data.staffAuthStatus === 2)

        }
      })
      .catch(error => {
        console.log(999)
        localStorage.removeItem('ep_Authorization');
        Vue.prototype.$message.error(`您的登录状态已失效，请先登录！`);
        next({ path: '/login' });
        // next({ path: '/login' });
      });

  },
  mounted () {
    this.url = process.env.VUE_APP_URL || '';
  },
  components: {}
};
</script>

<style lang="css" scoped>
.home {
    width: 100%;
    background: rgba(246, 246, 248, 1);
    opacity: 1;
}

.mt20 {
    margin-top: 20px;
}
.logo {
    height: 130px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
</style>